public final class Singleton2 {
    private static Singleton2 instance;
//    private static final ReentrantLock lock = new ReentrantLock();
    private static final Object lock = new Object();

    private Singleton2() {}

//    public static Singleton2 getInstance() {
//        if (instance == null) {
//            lock.lock();
//            if (instance == null) {
//                instance = new Singleton2();
//            }
//            lock.unlock();
//        }
//        return instance;
//    }

    public static Singleton2 getInstance() {
        synchronized (lock) {
            if (null == instance) {
                instance = new Singleton2();
            }
        }
        System.gc();
        return instance;
    }

    public static void main(String[] args) {
        for (String arg : args) {
            System.out.print(arg + " ");
        }
        System.out.println();
    }
}
